/**
*  
* @Function 数据质量报告服务
* @ProjectName credit-data-platform 
* @PackageName com.py.credit.service.impl    
* @FileName DataQualityServiceImpl.java    
* @Date 2018年7月11日上午10:22:36
* @Author Min DongXv
* @Copyright (c) 2018, 金电联行 All Rights Reserved.   
*   
*/
package com.py.credit.service.impl;

import java.io.File;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.py.credit.dao.DataQualityDao;
import com.py.credit.entity.DataQualityCollectionEntity;
import com.py.credit.entity.DataQualityDetailEntity;
import com.py.credit.entity.DataQualityEntity;
import com.py.credit.service.DataQualityService;
import com.py.credit.utils.FileUtil;
import com.py.credit.utils.HtmlToPdfUtils;
import com.py.credit.utils.SQLBuilder;
import com.py.framework.core.common.Page;

/**
 * 
 * @Function 数据质量报告服务
 * @ClassName DataQualityServiceImpl
 * @Date 2018年7月11日 上午10:22:36
 * @Author Min DongXv
 * 
 */
@Service
public class DataQualityServiceImpl implements DataQualityService {

	// 工商信息表
	private static final String REGISTER_TABLE_NAME = "100000460009_jnuqj847ju";
	// 自然人行政处罚
	private static final String ZRR_PUNISH = "1000010010004_KFPULZpF7D";
	// 法人行政处罚
	private static final String FR_PUNISH = "1000000010002_XSni4zSzP0";
	// 自然人行政许可
	private static final String ZRR_PERMIT = "1000010010003_vVwjDLoDWy";
	// 法人行政许可
	private static final String FR_PERMIT = "1000000010001_3ioj4GeZQU";

	private static final long DAY_MILL_SECONDS = 24 * 60 * 60 * 1000L;

	@Autowired
	private DataQualityDao dataQualityDao;

	/**
	 * 
	 * @Function 分页查询数据质量报告
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName dataQualityListByConditionForPage
	 * @param columns
	 * @param additionalColumns
	 * @param page
	 * @param condition
	 * @return
	 * @Date 2018年7月11日 下午2:31:39
	 * @Author Min DongXv
	 *
	 */
	@Override
	public List<Map<String, Object>> dataQualityListByConditionForPage(List<String> columns, String[] additionalColumns,
			Page page, String condition) {
		List<String> conditions = SQLBuilder.createConditionSql(condition);
		return dataQualityDao.dataQualityListByConditionForPage(columns, additionalColumns, page, conditions);
	}

	/**
	 * 
	 * @Function 获取数据质量报告详情
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName dataQualityDetail
	 * @param id
	 *            数据质量报告详情ID
	 * @return
	 * @Date 2018年7月11日 下午2:32:28
	 * @Author Min DongXv
	 *
	 */
	@Override
	public DataQualityDetailEntity dataQualityDetail(String dateRange) {
		return dataQualityDao.dataQualityDetail(dateRange);
	}

	/**
	 * 
	 * @Function 新增数据质量报告记录
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName addDataQuality
	 * @param entity
	 * @return
	 * @Date 2018年7月11日 下午2:34:53
	 * @Author Min DongXv
	 *
	 */
	@Override
	public int addDataQuality(DataQualityEntity entity) {
		return dataQualityDao.addDataQuality(entity);
	}

	/**
	 * 
	 * @Function 新增数据质量报告详情信息
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName addDataQualityDetail
	 * @param entity
	 * @Date 2018年7月11日 下午2:36:10
	 * @Author Min DongXv
	 *
	 */
	@Override
	public void addDataQualityDetail(DataQualityDetailEntity entity) {
		dataQualityDao.addDataQualityDetail(entity);
	}

	/**
	 *
	 * @Function 逻辑删除数据质量报告
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName updateDataQuality
	 * @param dateRange
	 * @Date 2018年7月11日 下午2:37:08
	 * @Author Min DongXv
	 *
	 */
	@Override
	public void updateDataQuality(String dateRange) {
		dataQualityDao.updateDataQuality(dateRange);
	}

	/**
	 *
	 * @Function 逻辑删除数据质量报告详情信息
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName updateDataQualityDetail
	 * @param dateRange
	 * @Date 2018年7月11日 下午2:37:54
	 * @Author Min DongXv
	 *
	 */
	@Override
	public void updateDataQualityDetail(String dateRange) {
		dataQualityDao.updateDataQualityDetail(dateRange);
	}

	/**
	 *
	 * @Function 通过期数获取数据质量报告信息
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName getDataQualityByDataRange
	 * @param dateRange
	 * @return
	 * @Date 2018年7月11日 下午2:38:44
	 * @Author Min DongXv
	 *
	 */
	@Override
	public DataQualityEntity getDataQualityByDataRange(String dateRange) {
		return dataQualityDao.getDataQualityByDataRange(dateRange);
	}

	/**
	 *
	 * @Function 下载数据质量报告PDF
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName pdfDownload
	 * @param fileName
	 * @param dateRange
	 * @Date 2018年7月11日 下午5:25:09
	 * @Author Min DongXv
	 *
	 */
	@Override
	public void pdfDownload(String absolutepath, String fileName, String dateRange, HttpServletResponse response) {
		FileUtil.downloadFile(buildDataQuality(absolutepath, fileName, dateRange), response);
	}

	/**
	 * 
	 * @Function 生成数据质量报告
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName dataQualityReport
	 * @param dateRange
	 * @param response
	 * @param request
	 * @Date 2018年7月16日 下午5:11:29
	 * @Author Min DongXv
	 *
	 */
	@Override
	@Transactional
	public void dataQualityReport(String wkpdfToolPath, String absolutepath, String dateRange,
			HttpServletResponse response, HttpServletRequest request) {
		dataQualityDao.updateDataQuality(dateRange);
		dataQualityDao.updateDataQualityDetail(dateRange);
		DataQualityEntity entity = new DataQualityEntity();
		DataQualityDetailEntity dEntity = new DataQualityDetailEntity();
		// 创建数据质量报告
		Map<String, Object> m = createDataQualityReport(dateRange);
		// 获取总体数据
		@SuppressWarnings("unchecked")
		Map<String, Object> total = (Map<String, Object>) m.get("total");
		String content = JSONObject.toJSONString(m);
		String fileName = createFileName(dateRange);
		// 数据质量报告前台地址
		StringBuffer url = request.getRequestURL();
		String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length())
				.append(request.getServletContext().getContextPath()).append("/").toString();
		// 本地测试使用
		// String tempContextUrl = "http://localhost:3000" +
		// request.getServletContext().getContextPath() + "/";
		String pageUrl = tempContextUrl + "dataQuality/dataQualityPdfReport.do?dateRange=" + dateRange;
		// 数据质量报告文件地址
		String pdfPath = absolutepath + "/dataQuality/" + dateRange + File.separator;
		entity.setDateRange(dateRange);
		entity.setDeptNum(Integer.parseInt(String.valueOf(total.get("deptNum"))));
		entity.setDataNum(Integer.parseInt(String.valueOf(total.get("tcount"))));
		entity.setFcount(Integer.parseInt(String.valueOf(total.get("fcount"))));
		entity.setScount(Integer.parseInt(String.valueOf(total.get("scount"))));
		entity.setRcount(Integer.parseInt(String.valueOf(total.get("rcount"))));
		entity.setWcount(Integer.parseInt(String.valueOf(total.get("wcount"))));
		entity.setSrate(String.valueOf(total.get("srate")));
		// 上传转换文件
		boolean pdfResult = HtmlToPdfUtils.convent(wkpdfToolPath, pageUrl, pdfPath, fileName, null);
		// 上传成功填入文件名称
		if (pdfResult) {
			entity.setFileName(fileName);
		}
		// 新增数据质量报告数据
		dataQualityDao.addDataQuality(entity);
		dEntity.setId(entity.getId());
		dEntity.setContent(content);
		dEntity.setDateRange(dateRange);
		// 新增数据质量报告详情
		dataQualityDao.addDataQualityDetail(dEntity);
	}

	/**
	 *
	 * @Function 生成文件名
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName createFileName
	 * @param dateRange
	 *            期数
	 * @Date 2018年7月11日 下午5:25:09
	 * @Author Min DongXv
	 *
	 */
	private String createFileName(String dateRange) {
		long head = System.currentTimeMillis() % (DAY_MILL_SECONDS);
		long body = Thread.currentThread().getId();
		int foot = ThreadLocalRandom.current().nextInt(9999);
		return "DQ-" + dateRange + "-" + head + "-" + body + "-" + foot;
	}

	/**
	 *
	 * @Function 上传转换PDF
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName createDataQualityReport
	 * @param
	 * @Date 2018年7月11日 下午5:25:09
	 * @Author Min DongXv
	 *
	 */
	// private RestServiceResult<Object> upLoadPdf(HttpServletRequest request,
	// String fileName, String pageUrl,
	// String pdfPath) {
	// RestServiceResult<Object> result = new RestServiceResult<Object>();
	// String basePath = request.getContextPath();
	// String path = request.getScheme() + "://" + request.getServerName() + ":"
	// +
	// request.getServerPort() + basePath;
	// String commond = "google-chrome --headless --disable-gpu --print-to-pdf="
	// +
	// pdfPath + fileName + ".pdf " + path
	// + pageUrl;
	// try {
	// Runtime.getRuntime().exec(commond);
	// return result;
	// } catch (Exception e) {
	// ExceptionLogger.error("DataQualityServiceImpl#upLoadPdf",
	// "上传转换PDF异常！ERROR："
	// + e.getMessage(), e);
	// result.setCode(RestServiceResult.CODE_UNKNOW);
	// result.setMsg("上传转换PDF异常！ERROR：" + e.getMessage());
	// return result;
	// }
	// }

	/**
	 *
	 * @Function 生成数据质量报告
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName createDataQualityReport
	 * @param dateRange
	 *            期数
	 * @Date 2018年7月11日 下午5:25:09
	 * @Author Min DongXv
	 *
	 */
	private Map<String, Object> createDataQualityReport(String dateRange) {
		// 返回数据Map
		Map<String, Object> data = new HashMap<String, Object>(16);
		// 问题列表集合
		List<String> problemList = new ArrayList<String>(2);
		// 获取时间数据
		Map<String, String> dates = dateDel(dateRange);
		String startTime = dates.get("startTime");
		String endTime = dates.get("endTime");
		// 获取总体信息
		Map<String, Object> total = dataQualityDao.getTotalData(startTime, endTime, null);
		int tcount = Integer.parseInt(String.valueOf(total.get("tcount")));
		int scount = Integer.parseInt(String.valueOf(total.get("scount")));
		int fcount = Integer.parseInt(String.valueOf(total.get("fcount")));
		int wcount = Integer.parseInt(String.valueOf(total.get("wcount")));
		int rcount = Integer.parseInt(String.valueOf(total.get("rcount")));
		String srate = "100%";
		String frate = "100%";
		String wrate = "100%";
		String rrate = "100%";
		DecimalFormat df = new DecimalFormat("0.00");
		if (tcount != 0) {
			srate = endWithZero(df.format((double) scount * 100 / tcount)) + "%";
			frate = endWithZero(df.format((double) fcount * 100 / tcount)) + "%";
			wrate = endWithZero(df.format((double) wcount * 100 / tcount)) + "%";
			double rate = (double) rcount * 100 / tcount;
			rrate = endWithZero(df.format(rate)) + "%";
			// 重复率>5%写入问题列表
			if (rate > 5) {
				String p = "重复数据过多,重复率：" + rrate;
				problemList.add(p);
			}
		}
		// 计算填充比率数据
		total.put("srate", srate);
		total.put("frate", frate);
		total.put("wrate", wrate);
		total.put("rrate", rrate);
		data.put("total", total);
		// 同比和环比数据
		String yearIncrease = "100%";
		String monthIncrease = "100%";
		if (tcount != 0) {
			// 获取去年同月的数据
			int y = dataQualityDao.getTotalCount(dates.get("yStartTime"), dates.get("yEndTime"), null);
			// 获取上月的数据
			int m = dataQualityDao.getTotalCount(dates.get("mStartTime"), dates.get("mEndTime"), null);
			if (y > 0) {
				yearIncrease = endWithZero(df.format((double) tcount * 100 / y)) + "%";
			}
			if (m > 0) {
				monthIncrease = endWithZero(df.format((double) tcount * 100 / m)) + "%";
			}
		}
		data.put("yearIncrease", yearIncrease);
		data.put("monthIncrease", monthIncrease);
		// 资源表top5
		List<Map<String, Object>> targetSumTop = dataQualityDao.getTargetSumTop(startTime, endTime);
		data.put("targetSumTop", targetSumTop);
		// 部门采集top5
		List<Map<String, Object>> deptSumTop = dataQualityDao.getDeptSumTop(startTime, endTime);
		data.put("deptSumTop", deptSumTop);
		// 数据归集质量分析
		List<DataQualityCollectionEntity> dataCollectionList = dataQualityDao.getDataCollectionList(startTime, endTime,
				null);
		data.put("dataCollectionList", dataCollectionList);
		// 获取部门入库率数据
		List<Map<String, Object>> deptRateTop = dataQualityDao.deptRateList(startTime, endTime, "D");
		List<Map<String, Object>> deptRateLast = dataQualityDao.deptRateList(startTime, endTime, "A");
		data.put("deptRateTop", deptRateTop);
		data.put("deptRateLast", deptRateLast);
		// 获取工商注册数据
		int registerTotal = 0;
		Integer id = dataQualityDao.getTableId(REGISTER_TABLE_NAME);
		List<DataQualityCollectionEntity> registerList = new ArrayList<DataQualityCollectionEntity>();
		if (null != id) {
			// 获取工商的成功入库数
			registerTotal = dataQualityDao.getSCount(startTime, endTime, id);
			// 获取工商的列表数据
			registerList = dataQualityDao.getDataCollectionList(startTime, endTime, id);
		}
		data.put("registerTotal", registerTotal);
		data.put("registerList", registerList);
		// 获取双公示数据
		List<String> resourceIds = new ArrayList<String>(4);
		resourceIds.add(ZRR_PERMIT);
		resourceIds.add(FR_PERMIT);
		resourceIds.add(ZRR_PUNISH);
		resourceIds.add(FR_PUNISH);
		// 获取行政处罚表ID
		Map<String, Object> administrationTotal = new HashMap<String, Object>(8);
		List<DataQualityCollectionEntity> administrationList = new ArrayList<DataQualityCollectionEntity>();
		int permitNum = 0;
		int punishNum = 0;
		// 及时入库总数
		int tNum = 0;
		List<Map<String, Object>> scatterList = new ArrayList<Map<String, Object>>();
		if (!CollectionUtils.isEmpty(resourceIds)) {
			// 获取双公示总体数据
			administrationTotal = dataQualityDao.getTotalData(startTime, endTime, resourceIds);
			// 获取双公示详情数据
			administrationList = dataQualityDao.getAdministrationList(startTime, endTime, resourceIds);
			if (!CollectionUtils.isEmpty(administrationList)) {
				// 及时率<=90 存入列表
				// List<String> tProblem = new ArrayList<>();
				Map<String, Integer> pDataMap = new HashMap<String, Integer>();
				// 获取行政处罚和行政许可数据
				List<Map<String, Object>> pData = dataQualityDao.getPermitPunishData(startTime, endTime);
				// 组装MAP
				if (!CollectionUtils.isEmpty(pData)) {
					for (Map<String, Object> pm : pData) {
						if (!CollectionUtils.isEmpty(pm) && null != pm.get("num")) {
							int n = Integer.parseInt(String.valueOf(pm.get("num")));
							pDataMap.put(pm.get("target") + "-" + pm.get("deptId"), n);
							tNum = tNum + n;
						}
					}
				}
				// 处理双公示列表数据
				for (DataQualityCollectionEntity e : administrationList) {
					if (null != e) {
						String resourceId = e.getResourceId();
						// 行政许可总数统计
						if (ZRR_PERMIT.equals(resourceId) || FR_PERMIT.equals(resourceId)) {
							permitNum = permitNum + e.getTcount();
						}
						// 行政处罚总数统计
						if (ZRR_PUNISH.equals(resourceId) || FR_PUNISH.equals(resourceId)) {
							punishNum = punishNum + e.getTcount();
						}
						int snum = e.getScount();
						// 默认及时率的100%
						String trate = "100%";
						Integer tnum = 0;
						if (snum != 0) {
							String tip = e.getTableId() + "-" + e.getDeptId();
							if (pDataMap.containsKey(tip)) {
								tnum = pDataMap.get(tip);
								double rate = (double) tnum / e.getScount();
								// 及时率不大于100%
								if (rate > 1) {
									rate = 1L;
								}
								trate = endWithZero(df.format(rate * 100)) + "%";
								// 记录及时率小于90%的数据到问题列表里面
								// if (rate <= 0.9) {
								// tProblem.add(e.getDeptName() + "上报" +
								// e.getTableName() + "及时率：" + trate);
								// }
							} else {
								// 没有上报数据，比率为0
								trate = "0";
								// 记录及时率小于90%的数据到问题列表里面
								// tProblem.add(e.getDeptName() + "上报" +
								// e.getTableName() + "及时率：0");
							}
						}
						e.setTrate(trate);
						// 填充散点图信息
						Map<String, Object> m = new HashMap<String, Object>(3);
						m.put("deptName", trate);
						m.put("tcount", e.getTcount());
						m.put("scount", tnum);
						scatterList.add(m);
					}
				}
			}
		}
		// 行政许可数量
		data.put("permitNum", permitNum);
		// 行政处罚数量
		data.put("punishNum", punishNum);
		// 双公示总数
		int sgsTotal = permitNum + punishNum;
		String trate = "100%";
		if (sgsTotal != 0) {
			double tr = (double) tNum / sgsTotal;
			trate = endWithZero(df.format(tr * 100)) + "%";
			if (tr < 0.9) {
				problemList.add("双公示数据及时率过低,及时率:" + trate);
			}
		}
		administrationTotal.put("trate", trate);
		// 行政处罚总体数据
		data.put("administrationTotal", administrationTotal);
		// 行政处罚列表数据
		data.put("administrationList", administrationList);
		// 散点图
		data.put("scatterList", scatterList);
		if (CollectionUtils.isEmpty(problemList)) {
			problemList.add("无");
		}
		// 问题列表
		data.put("problemList", problemList);
		return data;
	}

	/**
	 *
	 * @Function 时间处理
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName dateDel
	 * @param dateRange
	 *            期数
	 * @Date 2018年7月11日 下午5:25:09
	 * @Author Min DongXv
	 *
	 */
	private Map<String, String> dateDel(String dateRange) {
		Map<String, String> dateMap = new HashMap<String, String>(6);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
		SimpleDateFormat edf = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
		Calendar calendar = Calendar.getInstance();
		if (StringUtils.isNotBlank(dateRange)) {
			String year = dateRange.substring(0, 4);
			String month = dateRange.substring(4, 6);
			calendar.set(Calendar.YEAR, Integer.parseInt(year));
			calendar.set(Calendar.MONTH, Integer.parseInt(month) - 1);
		}
		// 设置为当月第一天
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		Date startDate = calendar.getTime();
		dateMap.put("startTime", sdf.format(startDate));
		// 设置为当月最后一天
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		Date endDate = calendar.getTime();
		dateMap.put("endTime", edf.format(endDate));
		// 去年 开始时间
		calendar.setTime(startDate);
		calendar.add(Calendar.YEAR, -1);
		dateMap.put("yStartTime", sdf.format(calendar.getTime()));
		// 去年 结束时间
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		dateMap.put("yEndTime", edf.format(calendar.getTime()));
		// 上月 开始时间
		calendar.setTime(startDate);
		calendar.add(Calendar.MONTH, -1);
		dateMap.put("mStartTime", sdf.format(calendar.getTime()));
		// 上月 结束时间
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		dateMap.put("mEndTime", edf.format(calendar.getTime()));
		return dateMap;
	}

	/**
	 *
	 * @Function 生成pdf路径
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName buildDataQuality
	 * @param fileName
	 * @param dateRange
	 * @Date 2018年7月11日 下午5:25:09
	 * @Author Min DongXv
	 *
	 */
	private String buildDataQuality(String absolutepath, String fileName, String dateRange) {
		return absolutepath + "/dataQuality/" + dateRange + File.separator + fileName + ".pdf";
	}

	/**
	 *
	 * @Function 去除计算的0
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName endWithZero
	 * @param rate
	 *            比率
	 * @Author Min DongXv
	 *
	 */
	private String endWithZero(String rate) {
		if (rate.contains(".")) {
			if (rate.endsWith("0")) {
				rate = rate.substring(0, rate.length() - 1);
			}
			if (rate.endsWith("0")) {
				rate = rate.substring(0, rate.length() - 2);
			}
		}
		return rate;
	}

	// public String createPdfHtml(String dateRange) {
	// StringBuilder sb = new StringBuilder();
	// sb.append("<!DOCTYPE html>");
	// sb.append("<html>");
	// sb.append("<head>");
	// sb.append("<meta charset='utf-8'>");
	// sb.append("<title>金电智诚</title>");
	// sb.append("<meta name='renderer' content='webkit'>");
	// sb.append("<meta http-equiv='X-UA-Compatible'
	// content='IE=edge,chrome=1'>");
	// sb.append(
	// "<meta name='viewport' content='width=device-width, initial-scale=1.0,
	// minimum-scale=1.0, maximum-scale=1.0, user-scalable=0'>");
	// sb.append("</head>");
	// sb.append("<body>");
	// sb.append(
	// "<iframe style='height:1000px;width:100%;'
	// src='http://localhost:3000/start/#/collectionSubsystem/dataQualityManagement/dataQualityReport/preview/dateRange="
	// + dateRange + "'>");
	// sb.append("</body>");
	// sb.append("</html>");
	// return sb.toString();
	// }

	/**
	 * 
	 * @Function 创建数据质量报告HTML
	 * @FileName DataQualityServiceImpl.java
	 * @MethodName createPdfHtml
	 * @param dateRange
	 * @return
	 * @Date 2018年7月31日 下午6:07:10
	 * @Author Min DongXv
	 *
	 */
	@Override
	public String createPdfHtml(String dateRange) {
		StringBuilder sb = new StringBuilder();
		DataQualityDetailEntity report = dataQualityDetail(dateRange);
		if (null != report) {
			String content = report.getContent();
			JSONObject jb = JSONObject.parseObject(content);
			JSONObject total = jb.getJSONObject("total");
			JSONArray deptSumTop = jb.getJSONArray("deptSumTop");
			JSONArray dataCollectionList = jb.getJSONArray("dataCollectionList");
			JSONArray targetSumTop = jb.getJSONArray("targetSumTop");
			// JSONArray scatterList = jb.getJSONArray("scatterList");
			// String punishNum = jb.getString("punishNum");
			// JSONArray deptRateTop = jb.getJSONArray("deptRateTop");
			JSONArray registerList = jb.getJSONArray("registerList");
			JSONObject administrationTotal = jb.getJSONObject("administrationTotal");
			JSONArray administrationList = jb.getJSONArray("administrationList");
			JSONArray problemList = jb.getJSONArray("problemList");
			// JSONArray deptRateLast = jb.getJSONArray("deptRateLast");
			
			//根据当前期数拼接时间
			int year = Integer.valueOf(dateRange.substring(0,4));
			int month = Integer.valueOf(dateRange.substring(4,dateRange.length()));
			int maxdata = getDaysByYearMonth(year,month);
			
			sb.append("<!DOCTYPE html>");
			sb.append("<html>");
			sb.append("<head>");
			sb.append("<meta charset='utf-8'>");
			sb.append("<title>质量报告</title>");
			sb.append("<meta name='renderer' content='webkit'>");
			sb.append("<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>");
			sb.append(
					"<meta name='viewport' content='width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0'>");
			sb.append("<script src='/web_site/start/js/echarts.min.js'></script>");
			sb.append("<script src='/web_site/start/js/html2canvas.js'></script>");
			sb.append("<script src='/web_site/start/js/jspdf.debug.js'></script>");


			sb.append(
					"<style>*{margin:0;padding:0}.clearBoth{zoom:1}.clearBoth:after{display:block;clear:both;content:\"\";visibility:hidden;height:0}body{font-family:\"Helvetica Neue\",Helvetica,Tahoma,Arial,sans-serif;font-size:12px}button,div,i,input,li,ul{-webkit-box-sizing:border-box;box-sizing:border-box}li,ul{list-style:none}table{border-collapse:collapse;border-spacing:0}.lay-dataQualityReportpreview{padding-bottom:20px;width:1200px}.lay-dataQualityReportpreview .previewtitle{width:193px;height:58px;font-size:32px;font-weight:700;margin-left:422px;margin-top:47px}.lay-dataQualityReportpreview .previewsub{width:400px;height:17px;margin-left:400px;font-size:16px;font-weight:600}.lay-dataQualityReportpreview .previewsubtitle{font-size:24px;font-weight:700;margin-left:80px;margin-top:50px}.lay-dataQualityReportpreview .previewdata{margin-left:80px;margin-top:0;font-size:15px}.lay-dataQualityReportpreview .previewdata p{font-size:15px;font-weight:400;margin-top:5px;margin-left:0}.lay-dataQualityReportpreview .previewdata i{font-size:14px;font-weight:400}.lay-dataQualityReportpreview .previewthtitle{font-size:24px;font-weight:700;margin-left:100px;margin-top:30px}.lay-dataQualityReportpreview .previewsubitem table{margin-left:100px;margin-top:20px;height:70px}.lay-dataQualityReportpreview .previewsubitem th{width:110px;height:35px;font-size:15px;font-weight:400;text-align:center}.lay-dataQualityReportpreview .previewsubitem td{width:110px;height:35px;font-size:15px;font-weight:400;text-align:center}.lay-dataQualityReportpreview .previewnumber{color:#1e9fff}.lay-dataQualityReportpreview .preview-item{font-size:15px;line-height:30px;margin-left:100px;padding-top:15px;padding-bottom:0}</style>");
			sb.append("</head>");
			sb.append("<body>");
			sb.append("<div class='lay-dataQualityReportpreview'>");
			sb.append("<div class='previewtop'>");
			sb.append("<div class='previewtitle' style='width:300px;'>数据质量报告");
			sb.append("<a href='javascript:void(0);' onclick='savePdf()' id='downloadPdf' style='text-decoration: none; font-size: 20px; margin-left: 20px;'>下载</a>");
			sb.append("</div>");
			sb.append("<div class='previewsub'>报告周期：" + year + "年"+month+"月"+"1日"+"-"+year + "年"+month+"月"+maxdata+"日");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("<div class='previewcontent'>");
			sb.append("<div class='partone' style='height:600px'>");
			sb.append("<div class='previewsubtitle'>一、数据质量总体情况");
			sb.append("</div>");
			sb.append("<div class='previewdata'>");
			sb.append("<p class='preview-item'>本期数据采集：");
			sb.append("<i style='color:red;font-weight:600;'>" + total.getString("tcount"));
			sb.append("</i>条；");
			sb.append("</p>");
			sb.append("<p class='preview-item'>数据采集同比增长：");
			sb.append("<i style='font-weight:600;'>").append(jb.getString("yearIncrease"))
					.append("</i>；&nbsp;&nbsp;&nbsp;&nbsp;环比增长");
			sb.append("<i style='font-weight:600;'>").append(jb.getString("monthIncrease")).append("</i>；");
			sb.append("</p>");
			sb.append("<p class='preview-item'>本期数据采集量最多的信息资源表TOP5：");
			if (null != targetSumTop && targetSumTop.size() > 0) {
				for (int i = 0; i < targetSumTop.size(); i++) {
					JSONObject j = targetSumTop.getJSONObject(i);
					sb.append("<span>" + j.getString("tableName") + "</span>；");
				}
			}
			sb.append("</p>");
			sb.append("<p class='preview-item'>本期数据采集量最多的部门TOP5：");
			if (null != deptSumTop && deptSumTop.size() > 0) {
				for (int i = 0; i < deptSumTop.size(); i++) {
					JSONObject j = deptSumTop.getJSONObject(i);
					sb.append("<span>" + j.getString("deptName") + "</span>；");
				}
			}
			sb.append("</p>");
			sb.append("</div>");
			sb.append("<div style='float:left;width:450px;height:350px;margin-left: 80px;'>");
			sb.append("<div id='previewchart1' style='float:left;width:450px;height:350px;margin-top:30px;'>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("<div style='float:left;width:350px;height:350px;'>");
			sb.append(
					"<div id='previewchart2' style='position:absolute;left:550px;width:350px;height:350px;margin-top:30px;'>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("<div class='parttwo'>");
			sb.append("<div class='previewquality'>");
			sb.append("<div class='previewsubtitle' style='margin-top:0px'>二、数据报送质量分析");
			sb.append("</div>");
			sb.append("<div class='previewsubitem' style=' overflow:hidden;'>");
			sb.append("<div class='previewthtitle'>2.1、数据归集质量分析");
			sb.append("</div>");
			sb.append("<div class='previewdata'>");
			sb.append("<p class='preview-item'>在此报告期间，约");
			sb.append("<i class='previewnumber'>").append(total.getString("deptNum")).append("</i>家信源单位提供了数据，提供记录总数：");
			sb.append("<i class='previewnumber'>").append(total.getString("tcount")).append("</i>条记录，符合归集质量要求");
			sb.append("<i class='previewnumber'>").append(total.getString("scount")).append("</i>条，归集质量比例：");
			sb.append("<i class='previewnumber'>").append(total.getString("srate")).append("</i>，").append("</p>");
			sb.append("<p class='preview-item'>归集异常记录数据：");
			sb.append("<i class='previewnumber'>").append(total.getString("fcount")).append("</i>，占归集总数比例：");
			sb.append("<i class='previewnumber'>").append(total.getString("frate")).append("</i>，重复记录数据：");
			sb.append("<i class='previewnumber'>").append(total.getString("rcount")).append("</i>，占归集总数比例：");
			sb.append("<i class='previewnumber'>").append(total.getString("rrate")).append("</i>，待关联记录数据：");
			sb.append("<i class='previewnumber'>").append(total.getString("wcount")).append("</i>，占归集总数比例：");
			sb.append("<i class='previewnumber'>").append(total.getString("wrate")).append("</i>");
			sb.append("</p>");
			sb.append("<p class='preview-item'>归集质量明细：");
			sb.append("</p>");
			sb.append("</div>");
			sb.append("<table class='dataTable' border='1'>");
			sb.append("<tr>");
			sb.append("<th>序号</th>");
			sb.append("<th>报送单位</th>");
			sb.append("<th>报送数据</th>");
			sb.append("<th>入库数</th>");
			sb.append("<th>异常数</th>");
			sb.append("<th>重复数</th>");
			sb.append("<th>待关联</th>");
			sb.append("<th>入库率</th>");
			sb.append("</tr>");
			if (null != dataCollectionList && dataCollectionList.size() > 0) {
				for (int i = 0; i < dataCollectionList.size(); i++) {
					JSONObject j = dataCollectionList.getJSONObject(i);
					sb.append("<tr>");
					sb.append("<td>" + (i + 1) + "</td>");
					sb.append("<td>" + j.getString("deptName") + "</td>");
					sb.append("<td>" + j.getString("tcount") + "</td>");
					sb.append("<td>" + j.getString("scount") + "</td>");
					sb.append("<td>" + j.getString("fcount") + "</td>");
					sb.append("<td>" + j.getString("rcount") + "</td>");
					sb.append("<td>" + j.getString("wcount") + "</td>");
					sb.append("<td>" + j.getString("srate") + "</td>");
					sb.append("</tr>");
				}
			}

			sb.append("</table>");
			sb.append("<div class='previewdata' style='margin-top:50px;'>本期数据采集")
					.append("<i class='previewnumber' style='color:red'>").append(total.getString("tcount"))
					.append("</i>条；&nbsp;&nbsp;&nbsp;&nbsp;其中，入库数：").append("<i class='previewnumber'>")
					.append(total.getString("scount")).append("</i>条；异常数：").append("<i class='previewnumber'>")
					.append(total.getString("fcount")).append("条</i>；重复数：").append("<i class='previewnumber'>")
					.append(total.getString("rcount")).append("条</i>；待关联数：").append("<i class='previewnumber'>")
					.append(total.getString("wcount")).append("条</i>；入库率：");
			sb.append("<iclass='previewnumber'>").append(total.getString("srate")).append("</i>；</div>");
			sb.append("<div style='margin-left:80px; overflow:auto;'>");
			sb.append("<div id='chart3' style='float:left;width:250px;height:250px;margin-top:30px;'>");
			sb.append("</div>");
			sb.append("<div id='chart3a' style='float:left;margin:65px 0 0 0;width:170px;height:170px'>");
			sb.append("</div>");
			sb.append("<div id='chart3b' style='float:left;margin:65px 0 0 0;width:170px;height:170px'>");
			sb.append("</div>");
			sb.append("<div id='chart3c' style='float:left;margin:65px 0 0 0;width:170px;height:170px'>");
			sb.append("</div>");
			sb.append("<div id='chart3d' style='float:left;margin:65px 0 0 0;width:170px;height:170px'>");
			sb.append("</div>");
			sb.append("<div id='chart3e' style='float:left;margin:65px 0 0 0;width:170px;height:170px'>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append(
					"<p style='font-size:24px;margin-top:70px;margin-left:350px' id='bmzlbg'>部门质量通报<span style='font-size:15px;'></span></p>");
			sb.append("<div style='margin-left:80px;overflow:auto;'>");
			sb.append("<div id='chart4' style='width:440px;height:300px;margin-top:30px;'>");
			sb.append("</div>");
			sb.append(
					"<div id='chart4a' style='width:440px;height:300px;margin-top:30px;'>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("<div class='previewsubitem'>");
//			sb.append("<div class='previewthtitle'>2.2、主数据分析</div>");
//			sb.append(
//					"<div class='previewdata' style='margin-top:70px;'>在此报告期间，企业主数据采用各级工商部门的“工商注册信息”，产生有效企业主数据量为<span style='color:blue'>")
//					.append(jb.getString("registerTotal")).append("</span>，分别产生如下企业主数据</div>");
//			sb.append("<table class='dataTable' style='margin-left:100px;' border='1'>");
//			sb.append("<tr>");
//			sb.append("<th>序号</th>");
//			sb.append("<th>报送单位</th>");
//			sb.append("<th>报送数据</th>");
//			sb.append("<th>入库数</th>");
//			sb.append("<th>异常数</th>");
//			sb.append("<th>重复数</th>");
//			sb.append("<th>正确率</th>");
//			sb.append("</tr>");
//			if (null != registerList && registerList.size() > 0) {
//				for (int i = 0; i < registerList.size(); i++) {
//					JSONObject j = registerList.getJSONObject(i);
//					sb.append("<tr>");
//					sb.append("<td>" + (i + 1) + "</td>");
//					sb.append("<td>" + j.getString("deptName") + "</td>");
//					sb.append("<td>" + j.getString("tcount") + "</td>");
//					sb.append("<td>" + j.getString("scount") + "</td>");
//					sb.append("<td>" + j.getString("fcount") + "</td>");
//					sb.append("<td>" + j.getString("rcount") + "</td>");
//					sb.append("<td>" + j.getString("srate") + "</td>");
//					sb.append("</tr>");
//				}
//			}
//			sb.append("</table>");
//			sb.append("</div>");
//			sb.append("<div class='previewsubitem'>");
			sb.append("<div class='previewthtitle'>2.2、专题数据分析</div>");
			sb.append("<div class='previewdata' style='margin-top:10px;'>");
			sb.append("<p class='preview-item'>在此报告期间，企业主数据采用各级部门的“行政许可”、“行政处罚”数据，产生有效双公示专题数据量为"
					+ administrationTotal.getString("tcount") + "，数据及时率为" + administrationTotal.getString("trate")
					+ "，</p>");
			sb.append("<p class='preview-item'>分别产生如下企业主数据</p>");
			sb.append("</div>");
			sb.append("<table class='dataTable' style='width:1000px;margin-left:100px;' border='1'>");
			sb.append("<tr>");
			sb.append("<th>序号</th>");
			sb.append("<th>信息资源表</th>");
			sb.append("<th>报送单位</th>");
			sb.append("<th>报送数据</th>");
			sb.append("<th>入库数</th>");
			sb.append("<th>异常数</th>");
			sb.append("<th>重复数</th>");
			sb.append("<th>正确率</th>");
			sb.append("<th>数据及时率</th>");
			sb.append("</tr>");
			if (null != administrationList && administrationList.size() > 0) {
				for (int i = 0; i < administrationList.size(); i++) {
					JSONObject j = administrationList.getJSONObject(i);
					sb.append("<tr>");
					sb.append("<td>" + (i + 1) + "</td>");
					sb.append("<td>" + j.getString("tableName") + "</td>");
					sb.append("<td>" + j.getString("deptName") + "</td>");
					sb.append("<td>" + j.getString("tcount") + "</td>");
					sb.append("<td>" + j.getString("scount") + "</td>");
					sb.append("<td>" + j.getString("fcount") + "</td>");
					sb.append("<td>" + j.getString("rcount") + "</td>");
					sb.append("<td>" + j.getString("srate") + "</td>");
					sb.append("<td>" + j.getString("trate") + "</td>");
					sb.append("</tr>");
				}
			}
			sb.append("</table>");
			sb.append("<div style='margin-left:80px;overflow:auto;'>");
			sb.append("<div id='chart5' style='float:left;width:330px;height:250px;margin-top:30px;'>");
			sb.append("</div>");
			sb.append("<div id='chart5a' style='float:left;margin:65px 20px 0 0;width:170px;height:170px'>");
			sb.append("</div>");
			sb.append("<div id='chart5b' style='float:left;margin:65px 20px 0 0;width:170px;height:170px'>");
			sb.append("</div>");
			sb.append("<div id='chart5c' style='float:left;margin:65px 20px 0 0;width:170px;height:170px'>");
			sb.append("</div>");
			sb.append("<div id='chart5d' style='float:left;margin:65px 20px 0 0;width:170px;height:170px'>");
			sb.append("</div>");
			sb.append("</div>");

			sb.append("<div style='margin-left:80px;overflow:auto;'>");
			sb.append("<div id='chart6' style='float:left;width:400px;height:300px;margin-top:30px;'>");
			sb.append("</div>");
			sb.append("<div id='chart7' style='float:left;width:600px;height:300px;margin-top:30px;'>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("<div class='partthree'>");
			sb.append("<div class='previewsubitem'>");
			sb.append("<div class='previewsubtitle'>三、数据质量改进建议</div>");
			sb.append("<div class='previewthtitle'>3.1、数据归集存在的问题</div>");
			sb.append("<div class='previewdata' style='margin-top:30px;'>在此报告期间，数据归集的主要存在以下问题：</div>");
			sb.append("<div class='previewproblem'>");
			sb.append("<ul>");
			if (null != problemList && problemList.size() > 0) {
				for (int i = 0; i < problemList.size(); i++) {
					String j = problemList.getString(i);
					sb.append("<li class='preview-item'>" + j + "</li>");
				}
			} else {
				sb.append("<li class='preview-item'>无</li>");
			}
			sb.append("</ul>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("</div>");
			sb.append("</body>");
			sb.append("<script>");
			sb.append("function savePdf() {");
			sb.append("document.getElementById('bmzlbg').style.marginTop = '470px';");
			sb.append("document.getElementById('downloadPdf').style.display = 'none';");
			sb.append("	var target = document.getElementsByClassName('lay-dataQualityReportpreview')[0];");
			sb.append("	target.style.background = '#FFFFFF';");
			sb.append("	html2canvas(target, {");
			sb.append("		onrendered:function(canvas) {");
			sb.append("			var contentWidth = canvas.width;");
			sb.append("			var contentHeight = canvas.height;");
			sb.append("			var pageHeight = contentWidth / 592.28 * 841.89;");
			sb.append("			var leftHeight = contentHeight;");
			sb.append("			var position = 0;");
			sb.append("			var imgWidth = 595.28;");
			sb.append("			var imgHeight = 592.28/contentWidth * contentHeight;");
			sb.append("			var pageData = canvas.toDataURL('image/jpeg', 1.0);");
			sb.append("			var pdf = new jsPDF('', 'pt', 'a4');");
			sb.append("			if (leftHeight < pageHeight) {");
			sb.append("				pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight );");
			sb.append("			} else {");
			sb.append("				while(leftHeight > 0) {");
			sb.append("					pdf.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight);");
			sb.append("					leftHeight -= pageHeight;");
			sb.append("					position -= 841.89;");
			sb.append("					if(leftHeight > 0) {");
			sb.append("						pdf.addPage();");
			sb.append("					}");
			sb.append("				}");
			sb.append("			}");
			sb.append("			pdf.save('数据质量报告").append(dateRange).append(".pdf');");
			sb.append("			document.getElementById('bmzlbg').style.marginTop = '70px';");
			sb.append("			document.getElementById('downloadPdf').style.display = 'inline';");
			sb.append("		}");
			sb.append("	});");
			sb.append("}");
			sb.append("var callbackData = ").append(jb).append(";");
			sb.append(
					"var previewchart1_xAxis=[],previewchart1_data=[];callbackData.targetSumTop.map(function(t){previewchart1_xAxis.push(t.tableName),previewchart1_data.push(t.count)}),console.log(previewchart1_xAxis);var myChart=echarts.init(document.getElementById(\"previewchart1\")),options={title:{text:\"本期数据采集量最多的信息资源表TOP5\",x:\"center\"},textStyle:{fontSize:11},color:[\"#79aab0\",\"#79aab0\",\"#79aab0\",\"#79aab0\",\"#79aab0\"],xAxis:{data:previewchart1_xAxis,splitNumber:6,axisLabel:{textStyle:{fontSize:11},rotate:-45},axisTick:{show:!1}},yAxis:{name:\"数量/条\",splitNumber:1,axisLabel:{formatter:\"{value}\"},axisline:{show:!0,lineStyle:{color:\"#ddd\"}},splitLine:{show:!0}},series:[{type:\"bar\",data:previewchart1_data,barWidth:30,itemStyle:{normal:{label:{show:!0,position:\"top\",formatter:\"{c}\"}}}}]};myChart.setOption(options);var previewchart2_xAxis=[],previewchart2_data=[];callbackData.deptSumTop.map(function(t){previewchart2_xAxis.push(t.deptName),previewchart2_data.push(t.count)});myChart=echarts.init(document.getElementById(\"previewchart2\")),options={title:{text:\"本期数据采集量最多的部门TOP5\",x:\"center\"},textStyle:{fontSize:11},xAxis:{data:previewchart2_xAxis,axisLabel:{textStyle:{fontSize:11},rotate:-45}},yAxis:{name:\"数量/条\",splitNumber:1,axisLabel:{formatter:\"{value}\"},splitLine:{show:!0}},color:[\"#91ca81\",\"#91ca81\",\"#91ca81\",\"#91ca81\",\"#91ca81\"],series:[{type:\"bar\",data:previewchart2_data,barWidth:30,itemStyle:{normal:{label:{show:!0,position:\"top\",formatter:\"{c}\"}}}}]};myChart.setOption(options);var chart3_data=[{value:callbackData.total.tcount/1e3}];console.log(callbackData);options={title:{text:\"本期数据采集总量\",subtext:\"单位：千\\n\",x:\"center\",itemGap:50},tooltip:{formatter:\"{a} <br/>{b} : {c}\",fontSize:20},series:[{type:\"gauge\",startAngle:240,endAngle:-60,min:0,max:100,precision:0,splitNumber:5,itemStyle:{normal:{color:\"#aaa\"}},pointer:{length:\"80%\",width:5,color:\"#999\"},detail:{show:!0,backgroundColor:\"auto\",width:80,height:30,offsetCenter:[\"0%\",100],formatter:\"{value}\",textStyle:{color:\"#eee\",fontSize:20}},axisLine:{show:!0,lineStyle:{width:10}},splitLine:{show:!0,length:10,lineStyle:{color:\"#eee\",width:2,type:\"solid\"}},axisLabel:{show:!0,formatter:function(t){switch(t+\"\"){case\"0\":return\"0\";case\"20\":return\"0.02\";case\"40\":return\"0.04\";case\"60\":return\"0.06\";case\"80\":return\"0.08\";case\"100\":return\"0.10\";default:return\"\"}}},data:chart3_data}]};(myChart=echarts.init(document.getElementById(\"chart3\"))).setOption(options);var chart3a_value=[callbackData.total.scount/1e3];console.log(callbackData);myChart=echarts.init(document.getElementById(\"chart3a\")),options={series:[{name:\"入库数\",type:\"pie\",radius:[\"55%\",\"70%\"],avoidLabelOverlap:!1,cursor:{fontSize:20},label:{normal:{show:!0,position:\"center\"},emphasis:{show:!0,textStyle:{fontSize:\"15\",fontWeight:\"bold\"}}},labelLine:{normal:{show:!1}},color:\"#1e9fff\",data:[{value:chart3a_value,name:chart3a_value+\"K\\n\\n入库数\",itemStyle:{normal:{color:new echarts.graphic.LinearGradient(1,0,0,0,[{offset:0,color:\"#508DFF\"},{offset:1,color:\"#26C5FE\"}])}}}]}]};myChart.setOption(options);var chart3b_value=[callbackData.total.fcount];console.log(callbackData);myChart=echarts.init(document.getElementById(\"chart3b\")),options={series:[{name:\"异常数\",type:\"pie\",radius:[\"55%\",\"70%\"],avoidLabelOverlap:!1,label:{normal:{show:!0,position:\"center\"},emphasis:{show:!0,textStyle:{fontSize:\"15\",fontWeight:\"bold\"}}},labelLine:{normal:{show:!1}},color:\"#5fb878\",data:[{value:chart3b_value,name:chart3b_value+\"\\n\\n异常数\",itemStyle:{normal:{color:new echarts.graphic.LinearGradient(1,0,0,0,[{offset:0,color:\"#63E587\"},{offset:1,color:\"#5FE2E4\"}])}}}]}]};myChart.setOption(options);var chart3c_value=[callbackData.total.rcount];console.log(callbackData);myChart=echarts.init(document.getElementById(\"chart3c\")),options={series:[{name:\"重复数\",type:\"pie\",radius:[\"55%\",\"70%\"],avoidLabelOverlap:!1,label:{normal:{show:!0,position:\"center\"},emphasis:{show:!0,textStyle:{fontSize:\"15\",fontWeight:\"bold\"}}},labelLine:{normal:{show:!1}},color:\"#AB82FF\",data:[{value:chart3c_value,name:chart3c_value+\"\\n\\n重复数\",itemStyle:{normal:{color:new echarts.graphic.LinearGradient(1,0,0,0,[{offset:0,color:\"#ffbfff\"},{offset:1,color:\"#AB82FF\"}])}}}]}]};myChart.setOption(options);var chart3d_value=[callbackData.total.wcount];console.log(callbackData);myChart=echarts.init(document.getElementById(\"chart3d\")),options={series:[{name:\"待关联数\",type:\"pie\",radius:[\"55%\",\"70%\"],avoidLabelOverlap:!1,label:{normal:{show:!0,position:\"center\"},emphasis:{show:!0,textStyle:{fontSize:\"15\",fontWeight:\"bold\"}}},labelLine:{normal:{show:!1}},color:\"#91ca81\",data:[{value:chart3d_value,name:chart3d_value+\"\\n\\n待关联数\",itemStyle:{normal:{color:new echarts.graphic.LinearGradient(1,0,0,0,[{offset:0,color:\"#508DFF\"},{offset:1,color:\"#26C5FE\"}])}}}]}]};myChart.setOption(options);var chart3e_value1=[callbackData.total.scount],chart3e_value2=[callbackData.total.tcount],chart3e_value=[];chart3e_value.push(Math.floor(chart3e_value1/chart3e_value2*100)),console.log(callbackData);myChart=echarts.init(document.getElementById(\"chart3e\")),options={series:[{name:\"入库率\",type:\"pie\",radius:[\"55%\",\"70%\"],avoidLabelOverlap:!1,label:{normal:{show:!0,position:\"center\",formatter:\"{c}%\\n\\n入库率\",precision:2},emphasis:{show:!0,textStyle:{fontSize:\"15\",fontWeight:\"bold\"}}},labelLine:{normal:{show:!1}},data:[{value:chart3e_value,precision:2,itemStyle:{normal:{color:new echarts.graphic.LinearGradient(1,0,0,0,[{offset:0,color:\"#ffb5b5\"},{offset:1,color:\"#ff7575\"}])}}}]}]};myChart.setOption(options);var chart4_yAxis=[],chart4_data=[];callbackData.dataCollectionList.map(function(t){chart4_yAxis.push(t.deptName)}),callbackData.deptRateTop.map(function(t){chart4_data.push(100*t.srate)});myChart=echarts.init(document.getElementById(\"chart4\")),"
					+ "options={title:{text:\"部门最高TOP5\",x:\"center\"},   grid: { left: \"30%\"  },xAxis:[{type:\"value\",position:\"top\",splitNumber:5,axisLabel:{formatter:\"{value}%\"},show:!1}],yAxis:[{type:\"category\",data:chart4_yAxis,max:4,axisLabel:{textStyle:{fontSize:9},rotate:-40},inverse:{default:!0},splitLine:{show:!0}}],color:[\"#6f8cde\",\"#6f8cde\",\"#6f8cde\",\"#6f8cde\",\"#6f8cde\"],"
					+ "series:[{name:\"部门最高TOP5\",type:\"bar\",barWidth:30,data:chart4_data,itemStyle:{normal:{label:{show:!0,position:\"right\",formatter:\"{c}%\"}}}}]};myChart.setOption(options);var chart4a_yAxis=[],chart4a_data=[];callbackData.deptRateLast.map(function(t){chart4a_yAxis.push(t.deptName),chart4a_data.push(t.srate*100)});myChart=echarts.init(document.getElementById(\"chart4a\")),"
					+ "options={title:{text:\"部门最低TOP5\",x:\"center\"},   grid: { left: \"30%\" },xAxis:[{type:\"value\",position:\"top\",axisLabel:{formatter:\"{value}%\"},splitNumber:5,min:0,max:100,show:!1}],yAxis:[{type:\"category\",data:chart4a_yAxis,axisLabel:{textStyle:{fontSize:9},rotate:-40},max:4,inverse:{default:!0},splitLine:{show:!0}}],"
					+ "series:[{name:\"部门最低TOP5\",type:\"bar\",barWidth:30,data:chart4a_data,itemStyle:{normal:{label:{show:!0,position:\"right\",formatter:\"{c}%\",precision:2}}}}]};myChart.setOption(options);var chart5_data=[{value:callbackData.administrationTotal.tcount/1e3}];console.log(callbackData);"
					+ "options={title:{subtext:\"单位：千\",x:\"center\"},tooltip:{formatter:\"{a} <br/>{b} : {c}\"},toolbox:{show:!0,feature:{mark:{show:!0}}},series:[{type:\"gauge\",startAngle:240,endAngle:-60,itemStyle:{normal:{color:\"#aaa\"}},min:0,max:100,precision:0,splitNumber:5,pointer:{length:\"80%\",width:5,color:\"#999\"},axisLine:{show:!0,lineStyle:{color:[[.2,\"#c23531\"],[.8,\"#63869e\"],[1,\"#91c7ae\"]],width:10}},splitLine:{show:!0,length:10,lineStyle:{color:\"#eee\",width:2,type:\"solid\"}},axisLabel:{show:!0,formatter:function(t){switch(t+\"\"){case\"0\":return\"0\";case\"20\":return\"0.02\";case\"40\":return\"0.04\";case\"60\":return\"0.06\";case\"80\":return\"0.08\";case\"100\":return\"0.10\";default:return\"\"}}},detail:{show:!0,backgroundColor:\"auto\",width:80,height:30,offsetCenter:[\"0%\",100],formatter:\"{value}\",textStyle:{color:\"#eee\",fontSize:20}},data:chart5_data}]};(myChart=echarts.init(document.getElementById(\"chart5\"))).setOption(options);var chart5a_value=[callbackData.administrationTotal.scount];console.log(callbackData);myChart=echarts.init(document.getElementById(\"chart5a\")),"
					+ "options={series:[{name:\"入库数\",type:\"pie\",radius:[\"55%\",\"70%\"],avoidLabelOverlap:!1,label:{normal:{show:!0,position:\"center\"},emphasis:{show:!0,textStyle:{fontSize:\"15\",fontWeight:\"bold\"}}},labelLine:{normal:{show:!1}},color:\"#1e9fff\",data:[{value:chart5a_value,name:chart5a_value+\"\\n\\n入库数\",itemStyle:{normal:{color:new echarts.graphic.LinearGradient(1,0,0,0,[{offset:0,color:\"#508DFF\"},{offset:1,color:\"#26C5FE\"}])}}}]}]};myChart.setOption(options);var chart5b_value=[callbackData.administrationTotal.fcount];console.log(callbackData);myChart=echarts.init(document.getElementById(\"chart5b\")),options={series:[{name:\"异常数\",type:\"pie\",radius:[\"55%\",\"70%\"],avoidLabelOverlap:!1,label:{normal:{show:!0,position:\"center\"},emphasis:{show:!0,textStyle:{fontSize:\"15\",fontWeight:\"bold\"}}},labelLine:{normal:{show:!1}},color:\"#5fb878\",data:[{value:chart5b_value,name:chart5b_value+\"\\n\\n异常数\",itemStyle:{normal:{color:new echarts.graphic.LinearGradient(1,0,0,0,[{offset:0,color:\"#63E587\"},{offset:1,color:\"#5FE2E4\"}])}}}]}]};myChart.setOption(options);var chart5c_value=[callbackData.administrationTotal.rcount];console.log(callbackData);myChart=echarts.init(document.getElementById(\"chart5c\")),options={series:[{name:\"重复数\",type:\"pie\",radius:[\"55%\",\"70%\"],avoidLabelOverlap:!1,label:{normal:{show:!0,position:\"center\"},emphasis:{show:!0,textStyle:{fontSize:\"15\",fontWeight:\"bold\"}}},labelLine:{normal:{show:!1}},color:\"#AB82FF\",data:[{value:chart5c_value,name:chart5c_value+\"\\n\\n重复数\",itemStyle:{normal:{color:new echarts.graphic.LinearGradient(1,0,0,0,[{offset:0,color:\"#ffbfff\"},{offset:1,color:\"#ab82ff\"}])}}}]}]};myChart.setOption(options);var chart5d_value=[callbackData.administrationTotal.wcount];console.log(callbackData);myChart=echarts.init(document.getElementById(\"chart5d\")),options={series:[{name:\"待关联数\",type:\"pie\",radius:[\"55%\",\"70%\"],avoidLabelOverlap:!1,label:{normal:{show:!0,position:\"center\"},emphasis:{show:!0,textStyle:{fontSize:\"15\",fontWeight:\"bold\"}}},labelLine:{normal:{show:!1}},color:\"#01aaed\",data:[{value:chart5b_value,name:chart5d_value+\"\\n\\n待关联数\",itemStyle:{normal:{color:new echarts.graphic.LinearGradient(1,0,0,0,[{offset:0,color:\"#508DFF\"},{offset:1,color:\"#26C5FE\"}])}}}]}]};myChart.setOption(options);var chart6_data=[{value:callbackData.permitNum,name:callbackData.permitNum+\"\\n行政许可\"},{value:callbackData.punishNum,name:callbackData.punishNum+\"\\n行政处罚\"}];console.log(callbackData);options={title:{text:\"本期行政许可与行政处罚数据占比\",x:\"center\"},tooltip:{trigger:\"item\",formatter:\"{b} : {c} ({d}%)\"},calculable:!0,series:[{type:\"pie\",radius:\"55%\",center:[\"50%\",\"60%\"],data:chart6_data,label:{normal:{position:\"inner\"}}}],color:[\"#d06a67\",\"#6f8cde\"]};(myChart=echarts.init(document.getElementById(\"chart6\"))).setOption(options);var chart7_xAxis=[],chart7_data=[],chart7_name=[];callbackData.scatterList.map(function(t){chart7_xAxis.push(t.tcount),chart7_data.push(t.scount),chart7_name.push(t.deptName)});myChart=echarts.init(document.getElementById(\"chart7\")),options={title:{text:\"本期双公示延时率\",x:\"center\"},tooltip:{trigger:\"axis\",showDelay:0,axisPointer:{show:!0,type:\"cross\",lineStyle:{type:\"dashed\",width:1}},formatter:function(t){return chart7_name[t[0].dataIndex]}},xAxis:{data:chart7_xAxis,name:\"总条数\",axisLabel:{textStyle:{fontSize:9}}},yAxis:{type:\"value\",name:\"按期上报正确条数\",scale:!0,splitNumber:5,axisLabel:{formatter:\"{value}\",textStyle:{fontSize:9},show:!0},min:0,splitLine:{show:!0}},color:\"#6f8cde\",series:[{type:\"scatter\",data:chart7_data,name:chart7_name}]};myChart.setOption(options);");
			sb.append("</script>");
			sb.append("</html>");
		}
		return sb.toString();
	}

	@Override
	public int getQulityReportNum() {

		return dataQualityDao.selectQulityReportNum();

	}
	

	
	 /** 
     * 根据年 月 获取对应的月份 天数 
     * */  
    public static int getDaysByYearMonth(int year, int month) {  


        Calendar a = Calendar.getInstance();  
        a.set(Calendar.YEAR, year);  
        a.set(Calendar.MONTH, month - 1);  
        a.set(Calendar.DATE, 1);  
        a.roll(Calendar.DATE, -1);  
        int maxDate = a.get(Calendar.DATE);  
        return maxDate;  
    }  
}
